package com.hopu.pojo;

import lombok.Data;

import java.io.Serializable;

/**
 * 通用响应实体
 */
@Data
public class R implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code = 200;
    private String message = "操作成功";
    private Object data;

    /**
     * 成功
     * @return
     */
    public static R ok(){
        return new R();
    }

    /**
     * 成功
     * @param message
     * @return
     */
    public static R ok(String message){
        R r = new R();
        r.message = message;
        return r;
    }

    /**
     * 成功
     * @param data
     * @return
     */
    public static R ok(Object data){
        R r = new R();
        r.data = data;
        return r;
    }

    /**
     * 成功
     * @param message
     * @param data
     * @return
     */
    public static R ok(String message, Object data){
        R r = new R();
        r.message = message;
        r.data = data;
        return r;
    }

    /**
     * 失败
     * @return
     */
    public static R err(){
        R r = new R();
        r.code = 500;
        return r;
    }

    /**
     * 失败
     * @param message
     * @return
     */
    public static R err(String message){
        R r = new R();
        r.code = 500;
        r.message = message;
        return r;
    }

    /**
     * 失败
     * @param data
     * @return
     */
    public static R err(Object data){
        R r = new R();
        r.code = 500;
        r.data = data;
        return r;
    }

    /**
     * 失败
     * @param message
     * @param data
     * @return
     */
    public static R err(String message, Object data){
        R r = new R();
        r.code = 500;
        r.message = message;
        r.data = data;
        return r;
    }

    public static R err(Integer code, String message){
        R r = new R();
        r.code = code;
        r.message = message;
        return r;
    }

}
